#include <dos.h>

#include "mouse.h"

#define MOUSEINT 0x33

int mouseInstalled()
	{
	union REGS regs;

	regs.h.ah = 0x00;
	int86(MOUSEINT,&regs,&regs);
	return(regs.x.ax == 0 || regs.x.ax == 2);
	}

void mouseCursorOn()
	{
	union REGS regs;

	regs.h.ah = 0x01;
	int86(MOUSEINT,&regs,&regs);
	}

void mouseCursorOff()
	{
	union REGS regs;

	regs.h.ah = 0x02;
	int86(MOUSEINT,&regs,&regs);
	}

void mouseRead(int *button, int *x, int *y)
	{
	union REGS regs;

	regs.h.ah = 0x03;
	int86(MOUSEINT,&regs,&regs);
	*button = regs.h.bh;
	*x = regs.x.cx;
	*y = regs.x.dx;
	}

void mouseMove(int x, int y)
	{
	union REGS regs;

	regs.h.ah = 0x04;
	regs.x.cx = x;
	regs.x.dx = y;
	int86(MOUSEINT,&regs,&regs);
	}

void mouseButtonPress(int *button, int *count, int *x, int *y)
	{
	union REGS regs;

	regs.h.ah = 0x05;
	int86(MOUSEINT,&regs,&regs);
	*button = regs.x.ax;
	*count = regs.x.bx;
	*x = regs.x.cx;
	*y = regs.x.dx;
	}

void mouseButtonRelease(int *button, int *count, int *x, int *y)
	{
	union REGS regs;

	regs.h.ah = 0x06;
	int86(MOUSEINT,&regs,&regs);
	*button = regs.x.ax;
	*count = regs.x.bx;
	*x = regs.x.cx;
	*y = regs.x.dx;
	}

void mouseLimit(int x1, int y1, int x2, int y2)
	{
	union REGS regs;

	regs.h.ah = 0x07;
	if (x1 <= x2)
		regs.x.cx = x1, regs.x.dx = x2;
	else
		regs.x.cx = x2, regs.x.dx = x1;
	int86(MOUSEINT,&regs,&regs);
	regs.h.ah = 0x08;
	if (y1 <= y2)
		regs.x.cx = y1, regs.x.dx = y2;
	else
		regs.x.cx = y2, regs.x.dx = y1;
	int86(MOUSEINT,&regs,&regs);
	}

void mouseDefineCursor(void far *Mask)
	{
	union REGS regs;
	struct SREGS sregs;

	regs.h.ah = 0x0A;
	regs.x.dx = FP_OFF(Mask);
	sregs.es = FP_SEG(Mask);
	int86x(MOUSEINT,&regs,&regs,&sregs);
	}

void mouseGetMove(int *dx, int *dy)
	{
	union REGS regs;

	regs.h.ah = 0x0B;
	int86(MOUSEINT,&regs,&regs);
	*dx = regs.x.cx;
	*dy = regs.x.dx;
	}

void mouseSetScale(int x, int y)
	{
	union REGS regs;

	regs.h.ah = 0x0F;
	regs.x.cx = x;
	regs.x.dx = y;
	int86(MOUSEINT,&regs,&regs);
	}

